<?php
namespace  app\home\widget;
use think\Controller;
use think\Db;
use think\Session;

class Cate extends Controller
{
    public function getcatebypid($pid)
    {
        $cate=Db::table('tp_category')->order('catorder','ASC')->where('pid',$pid)->select();
        $datas=[];
        //遍历
        foreach ($cate as $key=>$value)
        {
            //shop下标用来存储当前子类信息
            $value['shop']=$this->getcatebypid($value['id']);
            $datas[]=$value;
        }
        return $datas;
    }

    public function header()
    {
        //计算出来当前用户的购物车的商品
        $uid=(Session::get('userinfo'))['user_id'];
        $cart=Db::name('cart_goods')
            ->alias('cg')
            ->join('cart c','cg.cart_id=c.id')
            ->join('goods g','cg.goods_id=g.id')
            ->where('c.uid',$uid)
            ->select();
        $this->assign('cart',$cart);


        $cate=$this->getcatebypid(0);
       return $this->fetch("public:header",['cate'=>$cate]);
    }

    public function footer()
    {

      return $this->fetch('public:footer');
    }
}
?>